﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Htss.Platform.Data;
using System.Web;
using System.Web.Security;

namespace DreamBox.DAL.User
{
    public class Login
    {

        /// <summary>
        /// 返回用户登录信息
        /// </summary>
        /// <param name="Email"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public DataTable UserLogin(string UserName, string Password)
        {
            DbAction db = new DbAction();
            string sql = "select UserID,GID,GroupName,UserName,Avatar,Location,IsStatus from dbox_v_userinfo where UserName=@UserName and Password=@Password and IsStatus=1";
            db.SetFields("UserName",UserName);
            db.SetFields("Password",Password);
            DataTable dt = db.Select(sql, true);
            if (dt.Rows.Count > 0)
            {
                UpdateLoginDate(int.Parse(dt.Rows[0]["UserID"].ToString()));
            }
            return dt;
        }
        /// <summary>
        /// 更新用户最后登录时间
        /// </summary>
        /// <returns></returns>
        public bool UpdateLoginDate(int UserID)
        {
            Htss.Platform.Data.DbAction action = new Htss.Platform.Data.DbAction("dbox_User");
            action.SetFields("UserID", UserID, DbFieldType.Condition);
            action.SetFields("LastLoginDate",DateTime.Now);
            return action.Update();
        }
    }
}
